

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:gczn_hd/app/core/values/App_img.dart';
import 'package:gczn_hd/app/core/values/app_colors.dart';
import 'package:gczn_hd/app/core/values/app_values.dart';
import '../../../../core/values/text_styles.dart';
import 'package:gczn_hd/app/modules/ppm/station/controllers/station_controller.dart';
import 'package:get/get.dart';

class StationList extends StatelessWidget{
  final StationController controller = Get.put(StationController());


  @override
  Widget build(BuildContext context) {

    const double boxWidth = 315;

    return Container(
      width: boxWidth.w,
      child: SingleChildScrollView(
        child: Obx(() => Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [1,2,3,4,5,6,7,8,9].map((item) => GestureDetector(
            onTap: (){
              controller.selectIdx(item);
            },
            child: _buildStation(controller.selectIdx.value == item),
          )).toList(),
        )),
      ),
    );
  }


  Widget _buildStation(bool select){

    return _buildStationBox(
        isSelected: select,
      child: Container(
        padding: EdgeInsets.only(left: AppValues.size20.w, top: AppValues.size20.h, right: AppValues.margin_12.w, bottom: AppValues.size20.h),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            _buildStationName(),
            SizedBox(height: AppValues.size20.h,),
            _buildStationMsg()
          ],
        ),
      )
    );

  }

  Widget _buildStationMsg(){
    const double progress = 0.25;


    return Container(
      child: Column(
        children: [
          _buildMsgItem(title: "任务单号", msg: "RO20241212"),
          _buildMsgItem(title: "在制品", msg: "颜色:清巧银+黑色智控方式:语音"),
          SizedBox(height: 5.h,),
          _buildMsgItem(title: "任务进度", msg: "120/500", progress: true, centesimal: progress),
        ],
      ),
    );
  }

  Widget _buildMsgItem({required String title, String? msg, double? centesimal, bool progress = false }){
    return Row(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        SizedBox(
          width: AppValues.size105.w,
          child: Text("$title：", style: submitButtonText.copyWith(fontSize: AppValues.size20.sp, color: submitButtonText.color?.withOpacity(AppValues.decimals8)),),
        ),
        if( !progress )
          Expanded(
            flex: 1,
            child: Text(msg??'', style: submitButtonText.copyWith(fontSize: AppValues.size20.sp,),),
          )
        else 
          ...[
            Expanded(
              flex: 1,
              child: Stack(
                children: [
                  LinearProgressIndicator(
                    value: centesimal, // 0.5 假设进度为50%
                    backgroundColor: const Color(0xFF1a5398),
                    minHeight: AppValues.size20.h,
                    borderRadius: BorderRadius.circular(AppValues.size20.r),
                    valueColor: const AlwaysStoppedAnimation<Color>(AppColors.processProgBtn),
                  ),
                  Positioned(
                    top: 0,
                    left: 0,
                    right: 0,
                    child: Center(
                      child: Text("$msg  ${(centesimal!*AppValues.size100).toStringAsFixed(2)}%", style: submitButtonText.copyWith(fontSize: AppValues.size16.sp,),),
                    ),
                  )
                ],
              ),
            )
          ]
      ],
    );
  }


/// 工位名称
  Widget _buildStationName(){
    const boxSize = Size(28.0, 32.0);

    return  Row(
      children: [
        Expanded(
          flex: 1,
          child: Text("工位Z01", maxLines: 1, overflow: TextOverflow.ellipsis, style: submitButtonText.copyWith(fontSize: AppValues.size24.sp),),
        ),
        SizedBox(
          width: boxSize.width.w, height: boxSize.height.h,
          child: Stack(
            children: [
              Positioned(
                child: Image.asset(AppImg.alarm, width: boxSize.width.w, height: boxSize.height.h,),
              ),
              Center(
                child: Text("10", style: submitButtonText.copyWith(fontSize: AppValues.margin_12.sp),),
              )
            ],
          ),
        )
      ],
    );
  }

// 工位外层总样式
  Widget _buildStationBox({required Widget child, bool isSelected = false}){
    Size boxSize = const Size(304.0, 212.0);
    Size boxSize2 = const Size(315.0, 212.0);



    return !isSelected ? Container(
      width: boxSize.width.w,
      // height: boxSize.height.h,
        margin: EdgeInsets.only(bottom: AppValues.size20.h),
      decoration: BoxDecoration(
        border: Border.all(
          color: const Color.fromRGBO(39, 65, 80, 1),
          width: 1.0,
        ),
        borderRadius: BorderRadius.circular(AppValues.margin_12.r),
        color: AppColors.gcznPrimaryColor,
      ),
      child: child
    ) : Container(
        width: boxSize2.width.w,
        // height: boxSize2.height.h,
        margin: EdgeInsets.only(bottom: AppValues.size20.h),
        decoration: const BoxDecoration(
          image:  DecorationImage(
            image: AssetImage(AppImg.stationBg),
            fit: BoxFit.fill,
            alignment: Alignment.centerRight,
          ),
        ),
        child: Container(
          padding: EdgeInsets.only(right: AppValues.margin_10.w),
          width: boxSize.width.w,
          // height: boxSize.height.h,
          child: child,
        )
    ) ;
  }


}